package com.shanzmoo.admin.web.store;

import com.shanzmoo.admin.domain.dto.StoreStockIoSaveDTO;
import com.shanzmoo.admin.domain.dto.StoreStockIoUpdateDTO;
import com.shanzmoo.admin.manager.store.StoreStockIoManager;
import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SHttpResponse;
import com.shanzmoo.db.store.entity.StoreStockIoEntity;
import com.shanzmoo.db.store.entity.query.StoreStockIoQuery;
import com.shanzmoo.db.store.entity.vo.StoreStockIoVO;
import com.shanzmoo.db.store.service.IStoreStockIoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 库存流水 控制层
 *
 * @author fs 2021-03-10
 */
@Api(tags = "库存流水")
@RestController
@RequestMapping("/store/stock-io")
public class StoreStockIoController {

    @Autowired
    private IStoreStockIoService storeStockIoService;
    @Autowired
    private StoreStockIoManager storeStockIoManager;

    @ApiOperation(value = "分页列表")
    @PostMapping("/pageList")
    public SHttpResponse<PageRespBase<StoreStockIoVO>> pageList(@Valid @RequestBody StoreStockIoQuery query) {
        PageRespBase<StoreStockIoVO> pageList = storeStockIoManager.queryPage(query);
        return SHttpResponse.ok(pageList);
    }

    @ApiOperation(value = "添加")
    @PostMapping("/add")
    public SHttpResponse<Boolean> add(@Valid @RequestBody StoreStockIoSaveDTO saveDto) {
        storeStockIoService.save(saveDto.convertEntity());
        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "删除")
    @GetMapping("/delete")
    public SHttpResponse<Boolean> deleteById(@RequestParam(value = "id") Integer id) {
        StoreStockIoEntity entity = new StoreStockIoEntity();
        entity.setId(id);
        entity.setDeleted(true);
        storeStockIoService.updateById(entity);
        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public SHttpResponse<Boolean> update(@Valid @RequestBody StoreStockIoUpdateDTO updateDto) {
        storeStockIoService.updateById(updateDto.convertEntity());
        return SHttpResponse.ok(Boolean.TRUE);
    }
 }
